package com.futuristik.objects;

import java.util.List;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.EdgeShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.World;

public class Edge {
	float x1, y1, x2, y2;
	public Body box;
	
	public Edge(float x1, float y1, float x2, float y2){
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	public void create(World w) {
		BodyDef def = new BodyDef();
		box = w.createBody(def);

		box.setUserData("worldEdge");

		EdgeShape poly = new EdgeShape();		
		poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
		Fixture tempFixture = box.createFixture(poly, 0);
		tempFixture.setFriction(0.2f);
		box.setTransform(x1, y1, 0);
		poly.dispose();
	}
	
	static public void generateWorldEdges(List<Edge> l, int width, int height){
		l.add(new Edge(width/2f, -height/2f, -width/2f, -height/2f));
		l.add(new Edge(-width/2f, -height/2f, -width/2f, height/2f));
		l.add(new Edge(-width/2f, height/2f, width/2f, height/2f));
		l.add(new Edge(width/2f, height/2f, width/2f, -height/2f));
	}
}

